package service;

import mapper.TransferFile;
import model.Bill;
import view.Home;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

/**
 * @InterfaceName: MainServices
 * @Description:服务类
 * @Author: YourName
 * @Date: 2024/12/24
 */
public class MainServices {
    /**
    *@Description:记录收入
    *@Author: DaDaGuai
    *@Date:
    */
    public String RecordIincome(Bill bill){
        Boolean b = false;
        //读取存储的money
        double money = TransferFile.loadNumber();
        //进行存储的money的相加
        double reMoney = money + bill.getMoney();
        //收入金钱的记录
        //支出money的记录
        double getIncome = TransferFile.getIncome();
        double reGetIncome = getIncome + bill.getMoney();
        TransferFile.inputIncome(reGetIncome);
        //存储money
        boolean saveNumber = TransferFile.saveNumber(reMoney);
        if (saveNumber){
            //记录账单
             b = TransferFile.RecordIincomeMapper(bill);
        }
       if (b){
           return "记录收入成功";
       }
       return "记录收入失败";
    }
    /**
    *@Description: 记录支出
    *@Author: DaDaGuai
    *@Date:
    */
    public String RecordExpenses(Bill bill){
        Boolean b = false;
        //读取存储的money
        double money = TransferFile.loadNumber();
        //判断是否超过本金
        if (money < bill.getMoney()){
            return "金额不足";
        }
        //进行存储的money的相加
        double reMoney = money - bill.getMoney();
        //支出money的记录
        double getRxpenses = TransferFile.getExpenses();
        double reGetRxpenses = getRxpenses + bill.getMoney();
        TransferFile.inputExpenses(reGetRxpenses);
        //存储money
        boolean saveNumber = TransferFile.saveNumber(reMoney);
        if (saveNumber){
            //记录账单
            b = TransferFile.RecordIincomeMapper(bill);
        }
        if (b){
            return "记录支出成功";
        }
        return "记录支出失败";
    }
    /**
    *@Description:查看所有账单
    *@Author: DaDaGuai
    *@Date:
    */
    public void ViewAllBills(){
        LinkedList<Bill> bills = TransferFile.readIncomeMapper();
        for (Bill bill: bills){
            Home.viveBill(bill);
        }
    }
    /**
    *@Description:查询账单
    *@Author: DaDaGuai
    *@Date:
    */
    public void AnViewAllBills(String inputTime){
        LinkedList<Bill> bills = TransferFile.readIncomeMapper();
        for (Bill bill: bills){
            if (bill.getInputTime().equals(inputTime)){
               Home.viveBill(bill);
            }
        }
    }
    /**
    *@Description:限额
     *@Author: DaDaGuai
    *@Date:
    */
    public String limitMoney(double limitMoney){
        boolean key = TransferFile.inputLimitMoney(limitMoney);
        if (key){
            return "设置限额成功";
        }
        return "设置限额失败";
    }



}
